﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;
public partial class admin_tap_chi_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
             int pageIndex = ConvertUtility.ToInt32(Request.QueryString["page"]);

            if (pageIndex > 0)
                bindTC(pageIndex);
            else
                bindTC(1);
            lblMessage.Text = "";
           

        }
        catch (Exception ex) { }
    }
    protected void bindTC(int pageIndex)
    {
        try
        {
            tapchi_Info[] lstContent = tapchi_Info.FindAll(Order.Desc("id"));
            repTC.DataSource = lstContent.Skip((pageIndex - 1) * 10).Take(10);
            repTC.DataBind();
            int totalPage = (int)Math.Ceiling(ConvertUtility.ToDouble(lstContent.Length) / 10);
            pagerbot.Text = ConvertUtility.buidPaging3(totalPage, pageIndex, HttpContext.Current.Request.Url.LocalPath);
        }
        catch (Exception ex) { }
    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            string[] arrKeyDel = hidKeyDel.Value.Split('|');

            for (int i = 0; i < arrKeyDel.Length - 1; i++)
            {
                tapchi_Info contenInfo = tapchi_Info.Find(Convert.ToInt32(arrKeyDel[i].Trim()));
                contenInfo.DeleteAndFlush();
            }
            Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery);

        }
        catch (Exception ex)
        {
            lblMessage.Text = "Có lỗi xảy ra. Hãy thử lại";
            fail.Visible = true;
        }
    }
   
}